async function register() {
  document
    .querySelector("#btn-register")
    .addEventListener("click", async function (e) {
      e.preventDefault();
      const form = document.querySelector(".register-form");
      const data = new serialize(form, { hash: true, empty: true });
      console.log(data);
      if (
        /^[a-zA-Z0-9]{8,30}$/.test(data["username"]) &&
        /^[a-zA-Z0-9]{6,30}$/.test(data["password"])
      ) {
        try {
          const res = await axios({
            url: "/register",
            method: "POST",
            data,
          });
          if (res.data.message === "注册成功") {
            pxmu.toast(res.data.message);
            setTimeout(() => {
              window.location.href = "./login.html";
            }, 2000);
          }
        } catch (error) {
          // console.dir(error)
          pxmu.toast(error.response.data.message);
        }
      } else {
        pxmu.toast("请输入合法字符");
      }
    });
}
register();
